/*
* @Author: zhaoxiaoyang
* @Date:   2016-08-26 11:17:58
* @Last Modified by:   zhaoxiaoyang
* @Last Modified time: 2021-08-20 18:00:47
*/

'use strict';

let os = require('os')
let IPv4Name = os.hostname()
let IpV4Addr
let networkInterfaces = os.networkInterfaces()
// let servPort = 7250;

/*
if (networkInterfaces().en0) {
    for(let i=0;i<networkInterfaces().en0.length;i++){
        if(networkInterfaces().en0[i].family=='IPv4'){
            IPv4=networkInterfaces().en0[i].address;
        }
    }
};
*/

let test = require('dns').lookup(IPv4Name, function (err, add, fam) {
    IpV4Addr = add
    console.log('local IP: ' + IpV4Addr)
    console.log('local Name: ' + IPv4Name)
});

for (let i in networkInterfaces) {
    for (let m = 0, link = networkInterfaces[i], l = link.length; m < l; m++) {
        if (link[m].family == 'IPv4' && link[m].address != '127.0.0.1') {
            IpV4Addr = link[m].address
            break
        }
    }
    if (IpV4Addr) break
}

// IpV4Addr = IPv4Name || IpV4Addr || 'localhost'
IpV4Addr = IpV4Addr || IPv4Name || 'localhost'




/**
 * [host exports]
 * @description
 * @type  {Object}
 * @param {String}  [localPath] [(X:/) + localPath + src]
 */
module.exports = {
    // servPort: servPort,
    // cdnPort: cdnPort,
    IpV4: IpV4Addr,
    servUrl: 'http://' + IpV4Addr,
    cdnUrl: 'http://' + IpV4Addr,
    bash: 'view'
}